package guoanmaker.operator.business.scheduled;

import java.io.UnsupportedEncodingException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import guoanmaker.operator.business.service.TrademarkAndPatentSearchService;

/**
 * 
* @ClassName: OperatorTrademarkGetToken.java 
* @Description: 商标查询 获取token定时任务（由于同一token在一天内有效   激活一次 token在30分钟内有效  30分钟后token会失效  需要再次激活）
* @author Cancerl
* @date 2018年1月4日
*  
 */

@Configuration
@EnableScheduling
@Component
public class OperatorTrademarkGetTokenTask {
	
	@Autowired
	TrademarkAndPatentSearchService trademarkAndPatentSearchService;
	
	/*每28分钟激活一次token（token每30分钟失效一次 则每20分钟激活一次  确保token有效）*/
	@Scheduled(cron="0 */20 * * * ?")
	public void activateToken(){
		try {
			trademarkAndPatentSearchService.getToken();
			System.out.println("activateToken");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			System.err.println("激活token  URLEncod异常");
		}
	}
	
	
	/*每日0点 执行一次 更换token*/
	@Scheduled(cron="0 0 0 * * ?")
	public void resetToken(){
		try {
			trademarkAndPatentSearchService.getToken();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			System.err.println("激活token  URLEncod异常");
		}
	}
}
